from core.basic.mcharacter import createCharacter
from routers.core.Auth import (
    AlterState,
    authorize,
    createToken,
)
from routers.core.Gzip import register_gzip_request
from utils.exception import ResponseException
from typing import List
from fastapi import APIRouter, Depends, Header, Request
from pydantic import BaseModel
from routers.core.Response import response, Return

infoRouter = APIRouter()

register_gzip_request(infoRouter)


class adventureinfo(BaseModel):
    name: str
    alters: List[str]



@infoRouter.get("/adventure")
async def get_adventure_info(request: Request):
    from dataFiles.adv import adventure
    return response(data=adventure)

@infoRouter.get('/token/get/{alter}', response_model=Return[str])
async def getToken(
    alter: str, request: Request, equVersion: str = "0"
):
    token = await createToken(alter, equVersion, redis=request.app.state.redis)
    return response(data=token)

@infoRouter.get('/character')
async def get_character_info(state: AlterState = Depends(authorize)):
    equVersion = state.equVersion
    if equVersion is None or equVersion == "":
        equVersion = "0"
    char = createCharacter(state.alter, state.equVersion)
    info = {}
    if char is not None:
        info = char.getInfo()
    return response(data=info)